<template>
	<view class="uni-padding-wrap">
		<view class="header">
			<image src="../../static/logo.png" class="logo" mode="widthFix"></image>
		</view>
		<view class="myform">
			<view class="row">
				<label>账号</label>
				<input type="text" value="" v-model="username" placeholder="请输入账号"/>
			</view>
			<view class="row">
				<label>密码</label>
				<input type="text" value="" password v-model="password" placeholder="请输入密码"/>
			</view>
		</view>
		<view class="footer">
			<button type="primary" @click="dologin">登录</button>
			<view class="nav">
				<navigator url="../reset/reset">忘记密码</navigator>
				<navigator url="../reg/reg">新用户注册</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				// websiteUrl:helper.websiteUrl,
				now:this.helper.now(),
				webtitle:this.webtitle,
				weburl:this.weburl,
				isActive:false,
				isActives:true,
				username:"",
				password:""
			}
		},
		onLoad() {
			
			
		},
		methods: {
			dologin:function(){
				//1.获取必要数据，用户名，密码
				// console.log(this.username,this.password);
				//生成签名
				let timestamp =  this.helper.now();
				let sign =  this.helper.setSign(['username='+this.username,"password="+this.password,'timestamp='+timestamp]);
				//2.发起请求（登录接口）
				uni.request({
				    url: this.helper.websiteUrl+'login?timestamp='+timestamp, //仅为示例，并非真实接口地址。
					method:"POST",
				    data: {
				        username: this.username,
						password:this.password
				    },
				    header: {
				        'sign': sign //自定义请求头信息
				    },
				    success: (res) => {
						if(res.data==404){
							uni.showToast({
								title:"服务器异常",
								icon:"none",
								position:"bottom"
							})
							return;
						}
				        //3.根据返回的结果判断登录状态，并且保存登录状态
						if(res.data.errorcode>0){
							uni.showToast({
								title:res.data.message,
								icon:"none"
							})
							return;
						}
						uni.setStorageSync('userinfo',res.data.data);
						uni.reLaunch({
							url:"../index/index"
						})
				    },
					fail:function(){
						uni.showToast({
							title:"接口异常",
							icon:"none"
						})
						return;
					}
				});
				
				// uni.setStorageSync('token',"123456");
				// uni.navigateTo({
				// 	url:"../index/index"
				// })
			}
		}
	}
</script>

<style>
	.active{
		font-size:20px;
		color:#FF0000;
	}
	.border{border:1px solid #006400;}
	.green{color:#006400;}
	.fontsize{font-size:30px;}
	.header{
		width: 100%;
		text-align: center;
		padding-top: 230upx;
	}
	.header .logo{
		width: 150upx;
	}
	.myform{margin-bottom: 114upx;}
	.myform .row{display: flex;flex-direction: row;justify-content: space-between;border-bottom: 1px solid #F6F6F6;line-height: 80upx;margin-bottom: 30upx;}
	.myform .row label{width: 80upx;}
	.myform .row input{flex: 1;text-align: right;}
	.footer{width: 612upx;margin:0 auto;margin-top: 136upx;}
	.footer button{height: 96upx;font-size:36upx;}
	.footer .nav{display: flex;flex-direction: row;justify-content: space-between;margin-top: 42upx;}
	.footer .nav navigator{color: #999999;}
</style>
